package com.twu.biblioteca;

/**
 * Created by sravanns on 09/06/14.
 */
/*job: represents ability to return a book*/
public class ReturnBook implements MenuAction {
    private Library library;

    private UserInterface UIApplication;

    public ReturnBook(Library obj, UserInterface ui) {
        library = obj;
        UIApplication =ui;
    }

    @Override
    public String toString() {
        return "Return Book";
    }

    @Override
    public Result performAction(String user) {
        UIApplication.display("Enter Book Name");
        String input = UIApplication.acceptTitle();
        Book book = library.getBookFromCatalogue(input);
        Result result=new Result();
        if (book != null) {
            if (library.returnBook(book,user)) {
                result.setResult("Thank you for returning the book.",true);

            } else
                result.setResult("That is not a valid book to return.",false);



        }
        else
        result.setResult("That book is not valid book in Library. please consider checking the spelling",true);

        return result;
    }
}


